package statistics.poznavaniTextu;

import stuff.FileManager;

import java.io.*;
import java.util.HashMap;

/*
*   File ACharakteristiky 
*   in package statistics.poznavaniTextu
*   was created by slaha
*   on 14.4.12 at 21:28.
*
*/
public class ACharakteristiky implements Serializable {
  final String jmenoSouboru = "analyzaTextu.svla";
  final String pocetSlovVRymu = "pocetSlovVRymu";

  final String agregaceA = "agregaceA";
  final String agregaceB = "agregaceB";

  final String prumerStr = "Prumer";
  final String odchylkaStr = "Odchylka";

  final String pocetSlov(int i) {
    if (i < 3) {
      return "pocetSlov12";
    } else if (i >= 10) {
      return "pocetSlov10plus";
    } else {
      return "pocetSlov" + i;
    }
  }

  final String asonance(int i) {
    if (i < 1 || i > 10) {
      return null;
    } else {
      return "asonance" + i;
    }
  }

  public void save(ACharakteristiky aCharakteristiky) {
    String jmeno = FileManager.getFolder() + "/" + jmenoSouboru;


    try {
      //use buffering
      OutputStream file = new FileOutputStream(jmeno);
      OutputStream buffer = new BufferedOutputStream(file);
      ObjectOutput output = new ObjectOutputStream(buffer);
      try {
        output.writeObject(aCharakteristiky);
      } finally {
        output.close();
      }
    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }

  public ACharakteristiky load() {
    ACharakteristiky a = null;
    String jmeno = FileManager.getFolder() + "/" + jmenoSouboru;
    try {
      //use buffering
      InputStream file = new FileInputStream(jmeno);
      InputStream buffer = new BufferedInputStream(file);
      ObjectInput input = new ObjectInputStream(buffer);
      try {
        //deserialize
        a  = (ACharakteristiky) input.readObject();
      } finally {
        input.close();
      }
    } catch (ClassNotFoundException ex) {
      ex.printStackTrace();
    } catch (IOException ex) {
      ex.printStackTrace();
    }
    return a;
  }

}

